/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aptech.BugRS.buz;

import com.aptech.BugRS.dao.ComplaintDAO;
import com.aptech.BugRS.enity.ComplaintDTO;
import java.util.ArrayList;

/**
 *
 * @author KISS
 */
public class ComplaintBUZ {

    ComplaintDAO dao = null;
    private String lastError = "";

    public ComplaintBUZ() {
        dao = new ComplaintDAO();
    }

    /**
     *
     * @param complaint
     * @return false if error else return true;
     */
    public boolean create(ComplaintDTO com) {
        if (!com.Validate()) {
            //this.lastError = history.getValidateDescription();
            setLastError("E_Complaint error");
            return false;
        }
        if (dao.isExits(com)) {
            this.lastError = dao.getLastError();
            return false;
        }
        if (!dao.Create(com)) {
            this.lastError = dao.getLastError();
            return false;
        }
        this.setLastError(dao.getLastError());
        return true;
    }

    /**
     * Read all complaint
     * @return list of complaint
     */
    public ArrayList<ComplaintDTO> findByAll() {
        return dao.ReadByAll();
    }

    /**
     * Read by ID
     * @param id
     * @return complaint
     */
    public ComplaintDTO findByID(int id) {
        return dao.ReadByID(id);
    }

    /**
     * Read by unreplied Complaint
     * @return list of Complaint
     */
    public ArrayList<ComplaintDTO> findByStatus0() {
        return dao.ReadByStatus0();
    }

    /**
     * Read by replied Complaint
     * @return list of Complaint
     */
    public ArrayList<ComplaintDTO> findByStatus1() {
        return dao.ReadByStatus1();
    }

    /**
     * update Complaint
     * @param complaint
     * @return boolean
     */
    public boolean store(ComplaintDTO com) {
        if (!com.Validate()) {
            setLastError("Entity Complaint Error");
            return false;
        }
        if (!dao.Update(com)) {
            this.lastError = dao.getLastError();
            return false;
        }
        setLastError(dao.getLastError());
        return true;
    }

    /**
     * update complaint by status
     * @param id
     * @param status
     * @return boolean
     */
    public boolean storeByStatus(int id, int status) {
        if (!dao.UpdateByStatus(status, status)) {
            this.lastError = dao.getLastError();
            return false;
        }
        setLastError(dao.getLastError());
        return true;
    }

    /**
     * @return the lastError
     */
    public String getLastError() {
        return lastError;
    }

    /**
     * @param lastError the lastError to set
     */
    public void setLastError(String lastError) {
        this.lastError = lastError;
    }
}
